package com.alibaba.citrus.cr.sales.plan.functions.salesplan;

import com.alibaba.citrus.cr.sales.plan.sdo.SalesPlanStatScItemSDO;
import com.alibaba.citrus.cr.sales.plan.api.statistics.SalesPlanScItemStatWriteService;

import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

@Component
public class SalesPlanScItemStatAbility {

    @Resource
    SalesPlanScItemStatWriteService salesPlanScItemStatWriteService;

    /**
     * 回复量>计划量则直接更新
     */
    public Boolean doSplit(List<SalesPlanStatScItemSDO> salesPlanScItemStatSDOS) {
        salesPlanScItemStatSDOS.forEach(scItemStatSDO -> {
            // 设置部门回复量,上中旬回复量=计划量
            BigDecimal taskMoney = new BigDecimal(scItemStatSDO.getTaskCount()).multiply(new BigDecimal(scItemStatSDO.getCostInsuranceFreight()));
            scItemStatSDO.setTaskMoney(taskMoney.longValue());
            //scItemStatSDO.setReturnCount(scItemStatSDO.getMonthCount());
            scItemStatSDO.setTaskCount(scItemStatSDO.getMonthCount());
            scItemStatSDO.setMonthFirstReturnCount(scItemStatSDO.getMonthFirstCount());
            scItemStatSDO.setMonthFirstTaskCount(scItemStatSDO.getMonthFirstCount());
            scItemStatSDO.setMonthMiddleReturnCount(scItemStatSDO.getMonthMiddleCount());
            scItemStatSDO.setMonthMiddleTaskCount(scItemStatSDO.getMonthMiddleCount());
            scItemStatSDO.setMonthLastReturnCount(scItemStatSDO.getMonthLastCount());
            scItemStatSDO.setMonthLastTaskCount(scItemStatSDO.getMonthLastCount());
            salesPlanScItemStatWriteService.editSalesPlanScItem(scItemStatSDO);
        });
        return true;
    }

    /**
     * 按照一定规则进行拆解
     *
     * @return
     */
    public Boolean doSplitByRule() {
        return true;
    }

}
